<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="/static/backend/Style/skin.css" />
    <script type="text/javascript" src="/static/jquery-3.3.1.min.js"></script>
</head>
    <body>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <!-- 头部开始 -->
            <tr>
                <td width="17" valign="top" background="/static/backend/Images/mail_left_bg.gif">
                    <img src="/static/backend/Images/left_top_right.gif" width="17" height="29" />
                </td>
                <td valign="top" background="/static/backend/Images/content_bg.gif">
                    <table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" background="/static/backend//static/backend/Images/content_bg.gif">
                        <tr><td height="31"><div class="title">添加产品</div></td></tr>
                    </table>
                </td>
                <td width="16" valign="top" background="/static/backend/Images/mail_right_bg.gif"><img src="/static/backend/Images/nav_right_bg.gif" width="16" height="29" /></td>
            </tr>
            <!-- 中间部分开始 -->
            <tr>
                <!--第一行左边框-->
                <td valign="middle" background="/static/backend/Images/mail_left_bg.gif">&nbsp;</td>
                <!--第一行中间内容-->
                <td valign="top" bgcolor="#F7F8F9">
                    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                        <!-- 空白行-->
                        <tr><td colspan="2" valign="top">&nbsp;</td><td>&nbsp;</td><td valign="top">&nbsp;</td></tr>
                        <tr>
                            <td colspan="4">
                                <table>
                                    <tr>
                                        <td width="100" align="center"><img src="/static/backend/Images/mime.gif" /></td>
                                        <td valign="bottom"><h3 style="letter-spacing:1px;">请按要求填写！</h3></td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <!-- 一条线 -->
                        <tr>
                            <td height="40" colspan="4">
                                <table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
                                    <tr><td></td></tr>
                                </table>
                            </td>
                        </tr>
                        <!-- 添加产品开始 -->
                        <tr>
                            <td width="2%">&nbsp;</td>
                            <td width="96%">
                                <table width="100%">
                                    <tr>
                                        <td colspan="2">
                                            <form action="/backend/product/product_update" method="post">
                                                {foreach $result as $val}
                                                <table width="100%" class="cont" id="cont">
                                                    <tr>
                                                        <td width="2%">&nbsp;</td>
                                                        <td width="15%">产品名称：</td>
                                                        <td width="25%"><input class="text" type="text" name="product_name" value="{$val.product_name}" /></td>
                                                        <td>设置产品名称</td>
                                                        <td width="2%">&nbsp;</td>
                                                    </tr>
                                                    <tr>
                                                        <td width="2%">&nbsp;</td>
                                                        <td>产品编号：</td>
                                                        <td width="20%"><input class="text" type="text" name="product_number" value="{$val.product_number}" /></td>
                                                        <td>设置产品编号</td>
                                                        <td width="2%">&nbsp;</td>
                                                    </tr>
                                                    <tr>
                                                        <td width="2%">&nbsp;</td>
                                                        <td>产品图片：</td>
                                                        <td width="20%"><input type="file" id="id-input-file-2" 
                                                }
                                            name="product_img" onchange="upimg(this)" />
                                            
                                            <img src="{$val.product_img}" id="img_view" style="width:200px;"/>
                                            <input type="hidden" name="imgSrc" value="" id="img_src_input"></td>
                                                        <td>上传产品图片</td>
                                                        <td width="2%">&nbsp;</td>
                                                    </tr>
                                                    <tr>
                                                        <td width="2%">&nbsp;</td>
                                                        <td>产品详情：</td>
                                                        <td width="20%"><textarea name="product_detail">{$val.product_detail}</textarea></td>
                                                        <td>设置产品编号</td>
                                                        <td width="2%">&nbsp;</td>
                                                    </tr>
                                                    <tr>
                                                        <td width="2%">&nbsp;</td>
                                                        <td>库存量：</td>
                                                        <td width="20%"><input class="text" style="width:50px;" type="text" name="product_count" value="{$val.product_count}" /></td>
                                                        <td>设置产品库存</td>
                                                        <td width="2%">&nbsp;</td>
                                                    </tr>
                                                    <tr>
                                                        <td width="2%">&nbsp;</td>
                                                        <td>产品价格：</td>
                                                        <td width="20%"><input class="text" style="width:100px;" type="text" name="product_price" value="{$val.product_price}" /></td>
                                                        <td>设置产品价格</td>
                                                        <td width="2%">&nbsp;</td>
                                                    </tr>
                                                    <tr>
                                                        <td>&nbsp;</td>
                                                        <td>产品分类：</td>
                                                        <td>
                                                            <select name="product_sort" id="product_sort">
                                                                <option  value="0">景点</option>
                                                                <option  value="1">酒店</option>
                                                                <option  value="2">餐厅</option>
                                                            </select>
                                                        </td>
                                                        <td>设置产品分类</td>
                                                        <td>&nbsp;</td>
                                                    </tr>
                                                    
                                                    <tr>
                                                        <td>&nbsp;</td>
                                                        <td colspan="3"><input class="btn" type="submit" value="提交" /></td>
                                                        <td>&nbsp;</td>
                                                    </tr>
                                                </table>
                                                {/foreach}
                                            </form>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td width="2%">&nbsp;</td>
                        </tr>
                        <!-- 添加产品结束 -->
                        <tr>
                            <td height="40" colspan="4">
                                <table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
                                    <tr><td></td></tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </td>
                <td background="/static/backend/Images/mail_right_bg.gif">&nbsp;</td>
            </tr>
            <!-- 底部部分 -->
            <tr>
                <td valign="bottom" background="/static/backend/Images/mail_left_bg.gif">
                    <img src="/static/backend/Images/buttom_left.gif" width="17" height="17" />
                </td>
                <td background="/static/backend/Images/buttom_bgs.gif">
                    <img src="/static/backend/Images/buttom_bgs.gif" width="17" height="17">
                </td>
                <td valign="bottom" background="/static/backend/Images/mail_right_bg.gif">
                    <img src="/static/backend/Images/buttom_right.gif" width="16" height="17" />
                </td>           
            </tr>
        </table>
    </body>
</html>
<script type="text/javascript">
  function upimg(obj) {
    if ( obj.value == "" ) return;
    var formdata = new FormData();
    formdata.append("product_img" , $(obj)[0].files[0]);//获取文件法二
    $.ajax({
        type : 'post',
        url : '/backend/product/upimg',
        data : formdata,
        cache : false,
        processData : false, // 不处理发送的数据，因为data值是Formdata对象，不需要对数据做处理
        contentType : false, // 不设置Content-type请求头
        success : function(ret){
            //console.log(232);
           
            $('#img_view').attr('src',ret);
            $('#img_src_input').val(ret);
        },
        error : function(){ }
    });
}

                var lengths = $(".cont option").length;//下拉项的长度    
                var status = '{$val.product_sort}';//option的value
                var obj=document.getElementById('product_sort');                
                for(var i=0;i<lengths;i++){   
                    if(status ==obj.options[i].value){       
                        obj.options[i].selected=true;       
                    }   
                }   
</script>
